<?php
/**
 * Created by PhpStorm.
 * User: fangwei
 * Date: 2019-08-06
 * Time: 23:24
 */

namespace App\Http\Controllers\Admin\Api;


use App\Http\Controllers\Controller;
use App\Http\Repositories\Services\IClientVisit;
use App\Http\Requests\Admin\ClientVisitDTO;
use App\Util\LayUiVo;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Lang;

class ClientVisitController extends Controller
{
    protected $clientVisitService;

    public function __construct(IClientVisit $clientVisitService)
    {
        $this->clientVisitService = $clientVisitService;
    }

    public function page(Request $request) {
        $search = [];
        if ($request->get('user_name')) {
            $search['user_name'] = $request->get('user_name');
        }

        if ($request->get('client_name')) {
            $search['client_name'] = $request->get('client_name');
        }

        if ($request->get('start_time')) {
            $search['start_time'] = $request->get('start_time');
        }

        if ($request->get('stop_time')) {
            $search['stop_time'] = $request->get('stop_time');
        }

        $dao = $this->clientVisitService->lists($search, $request->get('page', 1), $request->get('limit','10'));
        return response()->json(new LayUiVo(['data'=>$dao,'message'=>Lang::get('response.success')]));
    }

    public function show($id) {
        $dao = $this->clientVisitService->byId($id);
        return response()->json(new LayUiVo(['data'=>$dao,'message'=>Lang::get('response.success')]));
    }

    public function store(ClientVisitDTO $clientVisitDTO){
        $this->clientVisitService->store($clientVisitDTO);
        return response()->json(new LayUiVo(['message'=>Lang::get('response.success')]));
    }

    public function update(ClientVisitDTO $clientVisitDTO,$id){
        $this->clientVisitService->update($clientVisitDTO,$id);
        return response()->json(new LayUiVo(['message'=>Lang::get('response.success')]));
    }

    public function delete($id){
        $this->clientVisitService->delete($id);
        return response()->json(new LayUiVo(['message'=>Lang::get('response.success')]));
    }

}